import { TransactionManager } from '@/uni_modules/stars-UniTS-SQLite-ORM/components/stars-UniTS-SQLite-ORM/dbOrm/TransactionManager/TransactionManager';


export function Transactional(target : any, propertyKey : string, descriptor : PropertyDescriptor) {
	const originalMethod = descriptor.value;
	descriptor.value = async function (...args : any[]) {
		const instance = this;
		const transactionManager = new TransactionManager();
		try {
			await transactionManager.beginTransaction();
			const result = await originalMethod.apply(instance, args);
			await transactionManager.commitTransaction();
			return result;
		} catch (error) {
			await transactionManager.rollbackTransaction();
			throw error;
		}
	};
	return descriptor;
}